﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;
namespace lcmyjobs.Web.admininfo
{
    public partial class Add : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["adminName"] != null)
                {
                    Bind();
                }
                else
                {
                    Maticsoft.Common.MessageBox.ResponseScript(this, "alert('请先登陆！');top.location.href='../adminlogin2.aspx'");
                }

            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {

            string strErr = "";

            if (this.txtaname.Text.Trim().Length == 0)
            {
                strErr += "用户名不能为空！\\n";
            }
            if (this.txtapwd.Text.Trim().Length == 0)
            {
                strErr += "密码不能为空！\\n";
            }


            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }

            string aname = this.txtaname.Text;
            string apwd = this.txtapwd.Text;
            apwd = myPublic.GetMd5(apwd);
            int atid = int.Parse(this.ddl_atid.SelectedItem.Value);

            lcmyjobs.Model.admininfo model = new lcmyjobs.Model.admininfo();
            model.aid = 0;
            model.aname = aname;
            model.apwd = apwd;
            model.atid = atid;
            model.truename = this.txttruename.Text;




            lcmyjobs.BLL.admininfo bll = new lcmyjobs.BLL.admininfo();
            bll.Add(model);
            Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功！", "add.aspx");

        }

        private void Bind()
        {
            lcmyjobs.BLL.admin_type bll = new lcmyjobs.BLL.admin_type();

            DataSet ds = bll.GetList("");

            this.ddl_atid.DataSource = ds;
            this.ddl_atid.DataTextField = "atname";
            this.ddl_atid.DataValueField = "atid";

            this.ddl_atid.DataBind();
        }


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}
